package com.zzdz.jdbc.common.exception;

import com.zzdz.jdbc.common.exception.enums.ExceptionCode;
import com.zzdz.jdbc.common.exception.enums.ExceptionCodeEnum;

/**
 * <p>
 * CustomRuntimeException<br>
 * 自定义运行异常
 * </p>
 *
 * @author XinLau
 * @version 1.0
 * @since 2019年10月16日 14:26
 */
public class CustomRuntimeException extends RuntimeException {

    /**
     * 异常代码
     */
    protected final ExceptionCode exceptionCode;

    /**
     * 获取异常信息
     * @return
     */
    public ExceptionCode getExceptionCode() {
        return exceptionCode;
    }

    /**
     * 无参默认构造 UNSPECIFIED
     */
    public CustomRuntimeException() {
        super(ExceptionCodeEnum.UNSPECIFIED.getExceptionDescription());
        this.exceptionCode = ExceptionCodeEnum.UNSPECIFIED;
    }

    /**
     * 指定错误码构造通用异常
     * @param exceptionCode - 异常信息
     */
    public CustomRuntimeException(final ExceptionCode exceptionCode) {
        super(exceptionCode.getExceptionDescription());
        this.exceptionCode = exceptionCode;
    }

    /**
     * 指定详细描述构造通用异常
     * @param detailedMessage 详细描述
     */
    public CustomRuntimeException(final String detailedMessage) {
        super(detailedMessage);
        this.exceptionCode = ExceptionCodeEnum.UNSPECIFIED;
    }

    /**
     * 指定导火索构造通用异常
     * @param throwable - 导火索
     */
    public CustomRuntimeException(final Throwable throwable) {
        super(throwable);
        this.exceptionCode = ExceptionCodeEnum.UNSPECIFIED;
    }

    /**
     * 构造通用异常
     * @param exceptionCode - 异常
     * @param detailedMessage - 详细描述
     */
    public CustomRuntimeException(final ExceptionCode exceptionCode, final String detailedMessage) {
        super(detailedMessage);
        this.exceptionCode = exceptionCode;
    }

    /**
     * 构造通用异常
     * @param exceptionCode - 异常
     * @param throwable - 导火索
     */
    public CustomRuntimeException(final ExceptionCode exceptionCode, final Throwable throwable) {
        super(exceptionCode.getExceptionDescription(), throwable);
        this.exceptionCode = exceptionCode;
    }

    /**
     * 构造通用异常
     * @param detailedMessage - 详细描述
     * @param throwable - 导火索
     */
    public CustomRuntimeException(final String detailedMessage, final Throwable throwable) {
        super(detailedMessage, throwable);
        this.exceptionCode = ExceptionCodeEnum.UNSPECIFIED;
    }

    /**
     * 构造通用异常
     * @param exceptionCode - 异常信息
     * @param detailedMessage - 详细描述
     * @param throwable - 导火索
     */
    public CustomRuntimeException(final ExceptionCode exceptionCode, final String detailedMessage, final Throwable throwable) {
        super(detailedMessage, throwable);
        this.exceptionCode = exceptionCode;
    }

}
